<html>
<head><meta charset="utf-8"><title>homogeneous aggregates · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html">homogeneous aggregates</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182696925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182696925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182696925">(Dec 05 2019 at 19:53)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> the PR <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/220" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/220">ucg#220</a> only provides the guarantee for tuples, tuple structs and arrays</p>



<a name="182696984"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182696984" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182696984">(Dec 05 2019 at 19:54)</a>:</h4>
<p>resolving <a href="https://github.com/rust-lang/unsafe-code-guidelines/issues/36" target="_blank" title="https://github.com/rust-lang/unsafe-code-guidelines/issues/36">ucg#36</a> as this guarantee not being provided for structs</p>



<a name="182697016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697016">(Dec 05 2019 at 19:54)</a>:</h4>
<p>I personally would prefer to just say something like:</p>
<blockquote>
<p>All homogeneous aggregates of the same <code>repr</code> and length share the same layout.</p>
</blockquote>



<a name="182697087"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697087" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697087">(Dec 05 2019 at 19:55)</a>:</h4>
<p>I see nothing about tuple structs in that diff</p>



<a name="182697113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697113">(Dec 05 2019 at 19:55)</a>:</h4>
<p>Tuples are defined as tuple structs in libcore IIRC</p>



<a name="182697162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697162">(Dec 05 2019 at 19:55)</a>:</h4>
<p>They are not, but that doesn't relate to what I said anyway</p>



<a name="182697259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697259">(Dec 05 2019 at 19:56)</a>:</h4>
<p>The diff only provides a guarantee for tuples, not for tuple structs</p>



<a name="182697281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697281">(Dec 05 2019 at 19:56)</a>:</h4>
<blockquote>
<p>an anonymous tuple type <code>(T1..Tn)</code> of arity N is laid out "as if" there were a corresponding tuple struct declared in libcore</p>
</blockquote>



<a name="182697291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697291">(Dec 05 2019 at 19:56)</a>:</h4>
<p>Oh that's what you mean</p>



<a name="182697336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697336">(Dec 05 2019 at 19:57)</a>:</h4>
<p>But still, the diff only provides a guarantee for tuples, not tuple structs in general</p>



<a name="182697353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697353">(Dec 05 2019 at 19:57)</a>:</h4>
<p>So if the layout of arrays and anonymous tuples match, so does the layout of arrays and tuple structs</p>



<a name="182697371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697371">(Dec 05 2019 at 19:57)</a>:</h4>
<p>otherwise, anonymous tuples cannot be laid out as tuple structs anymore</p>



<a name="182697400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697400">(Dec 05 2019 at 19:58)</a>:</h4>
<p>That might mean your diff is contradictory as is but it still doesn't say anything about tuple structs</p>



<a name="182697441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697441">(Dec 05 2019 at 19:58)</a>:</h4>
<p>I could add "homogeneous tuples and homogeneous tuple structs" to make that clearer</p>



<a name="182697459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697459">(Dec 05 2019 at 19:58)</a>:</h4>
<p>My diff doesn't say anything about tuple structs because it doesn't have to</p>



<a name="182697486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697486">(Dec 05 2019 at 19:58)</a>:</h4>
<p>We have already specified that the layout of anonymous tuples and tuple structs is exactly the same</p>



<a name="182697511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697511">(Dec 05 2019 at 19:58)</a>:</h4>
<p>Or at least, that's how I understood that sentence.</p>



<a name="182697546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697546">(Dec 05 2019 at 19:59)</a>:</h4>
<p>Maybe that wasn't the intent, and two identically defined tuple structs are allowed to have different layouts? No idea.</p>



<a name="182697684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697684">(Dec 05 2019 at 20:00)</a>:</h4>
<p>It says tuples are like particular tuple structs, but tuple struct layout is still generally not defined, so structurally identical tuple structs can have different layout</p>



<a name="182697764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697764">(Dec 05 2019 at 20:01)</a>:</h4>
<p>Ah, ok.</p>



<a name="182697798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697798">(Dec 05 2019 at 20:01)</a>:</h4>
<p>But none of what you propose has any consensus anyway</p>



<a name="182697811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697811">(Dec 05 2019 at 20:01)</a>:</h4>
<p>Then I think we should just say something about homogeneous aggregates in general, because if I say something about tuple structs, then I'm also saying something about structs.</p>



<a name="182697842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182697842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182697842">(Dec 05 2019 at 20:01)</a>:</h4>
<p>(tuple structs are just structs with fields named after the integers)</p>



<a name="182698052"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182698052" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182698052">(Dec 05 2019 at 20:03)</a>:</h4>
<p>I really don't want to open that controversial discussion again. It's not even the current active topic and I don't expect we'd get consensus this time around</p>



<a name="182698590"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182698590" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182698590">(Dec 05 2019 at 20:09)</a>:</h4>
<p>What is the controversy in <a href="https://github.com/rust-lang/rust/issues/36" target="_blank" title="https://github.com/rust-lang/rust/issues/36">#36</a> ?</p>



<a name="182698712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182698712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182698712">(Dec 05 2019 at 20:10)</a>:</h4>
<p>The main arguments against guaranteeing the layout of homogeneous aggregates was PGO or raising the alignment, but it was proposed that doing that could be done using specific repr attributes (e.g. <code>repr(opt)</code>) or similar, which IMO makes sense.</p>



<a name="182698837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182698837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182698837">(Dec 05 2019 at 20:12)</a>:</h4>
<p>With all due respect for your personal preferences, we've had plenty of comments explicitly not being convinced by that proposal since it was made</p>



<a name="182699095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182699095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182699095">(Dec 05 2019 at 20:15)</a>:</h4>
<p>And fwiw we also haven't made layout of other structs "deterministic w.r.t. field types"/structural because of the exact same concerns.</p>



<a name="182699796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182699796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182699796">(Dec 05 2019 at 20:22)</a>:</h4>
<p>The only concerns I see broken by the definition are:</p>
<ul>
<li>being able to re-order fields of homogeneous structs (e.g. using PGO to avoid false-sharing, or put hot fields together)</li>
<li>having to define what homogeneous mean</li>
<li>possible performance gap between homogeneous and heterogeneous aggregates</li>
</ul>



<a name="182699811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182699811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182699811">(Dec 05 2019 at 20:23)</a>:</h4>
<p>Are there any others ?</p>



<a name="182700126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182700126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182700126">(Dec 05 2019 at 20:26)</a>:</h4>
<p>There are others but what you've listed is already <em>plenty</em></p>



<a name="182700170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182700170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182700170">(Dec 05 2019 at 20:27)</a>:</h4>
<p>By that I mean there is absolutely no basis for nailing down their layout atm, it will require more consensus building, and IMO this is absolutely not a good use of anyone's time at the moment</p>



<a name="182700312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182700312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182700312">(Dec 05 2019 at 20:28)</a>:</h4>
<p>Using PGO to avoid false-sharing is horrible, defining what homogeneous means is trivial, and for there to be a possible performance gap between homogeneous and heterogeneous aggregates somebody would need to mention an optimization that would be possible for heterogeneous aggregates that wouldn't be possible for homogeneous ones.</p>



<a name="182700344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182700344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182700344">(Dec 05 2019 at 20:29)</a>:</h4>
<p>The only one that has been mentioned is field-reordering via PGO.</p>



<a name="182701948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182701948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182701948">(Dec 05 2019 at 20:49)</a>:</h4>
<p>That's not true (just off the top of my head there's field randomization and raising alignment) but more importantly, as I said before, if we let things like hypothetical possibility of PGO stop us from nailing down layout of general structs further (and that's the status quo, like it or not!) then it should also stop us from nailing down layout of homogeneous structs specifically, because there's no reason PGO would apply any less to those structs.</p>



<a name="182706709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182706709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182706709">(Dec 05 2019 at 21:31)</a>:</h4>
<p>I've replied to the issue with a summary</p>



<a name="182706824"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182706824" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182706824">(Dec 05 2019 at 21:32)</a>:</h4>
<p>If we guarantee the field order for these types, then code that relies on that is correct, so I wasn't sure what the point of field randomization would be (it would break correct code).</p>



<a name="182706949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182706949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182706949">(Dec 05 2019 at 21:33)</a>:</h4>
<p>Raising the alignment up to the size is allowed. Raising the alignment beyond the size has the consequence of increasing the size of the aggregate.</p>



<a name="182707024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182707024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182707024">(Dec 05 2019 at 21:34)</a>:</h4>
<p>That might be worth it in some cases, but can be done with <code>#[repr(align())]</code>, and instead of doing this silently, e.g., with PGO, we could just tell the user "If you want faster code add <code>repr(align(N))</code> here.</p>



<a name="182707223"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182707223" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182707223">(Dec 05 2019 at 21:36)</a>:</h4>
<p>Field re-ordering due to PGO still sounds to me like the best reason for not doing this, and I get the point that if it is not worth it for homogeneous struct, why would it be worth it for heterogeneous ones?</p>



<a name="182707332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182707332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182707332">(Dec 05 2019 at 21:37)</a>:</h4>
<p>Jesus, are you still at it? I would like more layout guarantees too but why the hell dig this specific thing up now? Either nobody bites and we don't get discussion and consensus, in which case all of this is a waste of time, or there's a huge discussion again and that is really not what UCG time should be spent on when even the current <em>active</em> topic (validity) is in limbo. Even assuming we end up with consensus.</p>



<a name="182707547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182707547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182707547">(Dec 05 2019 at 21:39)</a>:</h4>
<blockquote>
<p>I would like more layout guarantees too but why the hell dig this specific thing up now?</p>
</blockquote>
<p>I was looking into safe transmutes, and ran into transmuting anonymous tuples into anything is unsound.</p>



<a name="182707769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182707769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182707769">(Dec 05 2019 at 21:41)</a>:</h4>
<p>I think it's sufficient for tuples to be unspecified because anyone who cares can make a struct with repr(C) on it</p>



<a name="182707949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182707949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182707949">(Dec 05 2019 at 21:42)</a>:</h4>
<p>That explains how the topic got your attention again, but not why it should be pursued so aggressively now. Nothing about any safe transmute design hinges on tuples specifically, some trait impls get added if/when tuple layout is defined and not having those impls affects nothing except the ability to transmute tuples (which is also impossible to do unsafely for lack of layout guarantees, so it's not a safe-transmute-specific problem)</p>



<a name="182708019"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182708019" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182708019">(Dec 05 2019 at 21:43)</a>:</h4>
<blockquote>
<p>hypothetical possibility of PGO stop us from nailing down layout of general structs further (and that's the status quo, like it or not!) then it should also stop us from nailing down layout of homogeneous structs specifically, because there's no reason PGO would apply any less to those structs.</p>
</blockquote>
<p>Beyond PGO, the layout of heterogeneous aggregates is also blocked on things like variadics, e.g., do we want to support slicing &amp;(A, B, C) into &amp;(A, b) and &amp;(B, C) )? Since that limits whether we can re-order the fields to reduce padding or not.</p>



<a name="182708305"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous%20aggregates/near/182708305" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/homogeneous.20aggregates.html#182708305">(Dec 05 2019 at 21:46)</a>:</h4>
<p>I'm opting out now (and muting this thread so I stick to it), I think I've made clear that I consider spending any time on this topic at this time is ill-advised and I've spent entirely too much time on it already</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>